package com.school.zhaoban.config;


/**
 * @author 又菜又爱玩
 * @version 1.0
 * @date 2022/2/19 14:12
 * @blog https://blog.csdn.net/biancheng4/article/details/121727982
 */


import com.school.zhaoban.response.ResultCode;

/**
 * 自定义业务异常类
 */
public class BusinessException extends RuntimeException {

    private ResultCode exceptionEnum;
    private int code;
    private String errorMsg;

    public BusinessException() {
        super();
    }

    public BusinessException(ResultCode exceptionEnum) {
        super("{code:" + exceptionEnum.getCode() + ",errorMsg:" + exceptionEnum.getMessage() + "}");
        this.exceptionEnum = exceptionEnum;
        this.code = exceptionEnum.getCode();
        this.errorMsg = exceptionEnum.getMessage();
    }

    public BusinessException(int code, String errorMsg) {
        super("{code:" + code + ",errorMsg:" + errorMsg + "}");
        this.code = code;
        this.errorMsg = errorMsg;
    }

    public BusinessException(int code, String errorMsg, Object... args) {
        super("{code:" + code + ",errorMsg:" + String.format(errorMsg, args) + "}");
        this.code = code;
        this.errorMsg = String.format(errorMsg, args);
    }

    public ResultCode getExceptionEnum() {
        return exceptionEnum;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}
